<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="采购订单号" prop="poId">
        <el-input
          v-model="queryParams.poId"
          placeholder="请输入采购订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="采购组织" prop="poOrg">
        <el-input
          v-model="queryParams.poOrg"
          placeholder="请输入采购组织"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="存货编码" prop="itemId">
        <el-input
          v-model="queryParams.itemId"
          placeholder="请输入存货编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="存货名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入存货名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商名称" prop="vendorName">
        <el-input
          v-model="queryParams.vendorName"
          placeholder="请输入供应商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['purchase:purchaseOrders:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['purchase:purchaseOrders:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleBatchDelete"
          v-hasPermi="['purchase:purchaseOrders:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['purchase:purchaseOrders:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="purchaseOrdersList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" width="80">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="采购订单号" align="center" prop="poId" width="150" />
      <el-table-column label="采购组织" align="center" prop="poOrg" width="120" />

      <!-- 存货信息字段 -->
      <el-table-column label="存货编码" align="center" prop="itemId" width="120" />
      <el-table-column label="存货名称" align="center" prop="itemName" width="150" />
      <el-table-column label="规格型号" align="center" prop="spec" width="120" />
      <el-table-column label="计量单位" align="center" prop="uom" width="80" />

      <!-- 供应商信息字段 -->
      <el-table-column label="供应商编码" align="center" prop="vendorId" width="120" />
      <el-table-column label="供应商名称" align="center" prop="vendorName" width="150" />

      <!-- 采购详情字段 -->
      <el-table-column label="订单数量" align="center" prop="poNum" width="100" />
      <el-table-column label="已打码数量" align="center" prop="codeNum" width="100" />
      <el-table-column label="未打码数量" align="center" prop="notcodeNum" width="100" />
      <el-table-column label="剩余数量" align="center" prop="remainingNum" width="100" />
      <el-table-column label="已送料数量" align="center" prop="payoffNum" width="100" />
      <el-table-column label="已拒收数量" align="center" prop="rejectNum" width="100" />
      <el-table-column label="已退货数量" align="center" prop="returnNum" width="100" />
      <el-table-column label="已收货数量" align="center" prop="receivedNum" width="100" />
      <el-table-column label="到货状态" align="center" prop="receivedStatus" width="100">
        <template slot-scope="scope">
          <el-tag :type="getReceiveStatusType(scope.row.receivedStatus)">
            {{ getReceiveStatusText(scope.row.receivedStatus) }}
          </el-tag>
        </template>
      </el-table-column>

      <!-- 时间字段 -->
      <el-table-column label="创建时间" align="center" prop="createdAt" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createdPerson" width="100" />
      <el-table-column label="更新时间" align="center" prop="updatedAt" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatedAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document-add"
            @click="handleGenerateBoxCode(scope.row)"
            v-hasPermi="['purchase:boxCodes:add']"
            :disabled="scope.row.notcodeNum < 0"
          >生成箱码</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleViewDetails(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['purchase:purchaseOrders:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['purchase:purchaseOrders:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改采购订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="采购订单号" prop="poId" :class="readonlyColorClass">
          <el-input v-model="form.poId" placeholder="请输入采购订单号"  :disabled="true" />
        </el-form-item>
        <el-form-item label="采购组织" prop="poOrg" :class="readonlyColorClass">
          <el-input v-model="form.poOrg" placeholder="请输入采购组织" :disabled="true" />
        </el-form-item>
        <el-form-item label="订单数量" prop="totalAmount" :class="readonlyColorClass">
          <el-input v-model="form.totalAmount" placeholder="请输入订单数量"  :disabled="true" />
        </el-form-item>
        <el-form-item label="交货日期" prop="deliveryDate">
          <el-date-picker clearable
                          v-model="form.deliveryDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择交货日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="创建人" prop="createdPerson" :class="readonlyColorClass">
          <el-input v-model="form.createdPerson" placeholder="当前用户"  :disabled="true"/>
        </el-form-item>

        <el-divider content-position="center">采购订单信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddPurchaseOrdersDetails">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeletePurchaseOrdersDetails">删除</el-button>
          </el-col>
        </el-row>
        <el-table :data="purchaseOrdersDetailsList" :row-class-name="rowPurchaseOrdersDetailsIndex" @selection-change="handlePurchaseOrdersDetailsSelectionChange" ref="purchaseOrdersDetails">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="序号" align="center" prop="index" width="50"/>
          <el-table-column label="存货编码" prop="itemId" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.itemId" placeholder="请输入存货编码" />
            </template>
          </el-table-column>
          <el-table-column label="订单数量" prop="poNum" width="150">
            <template slot-scope="scope">
              <el-input
                v-model.number="scope.row.poNum"
                placeholder="请输入订单数量"
                type="number"
                min="0"
                @change="calculateTotalAmount"
              />
            </template>
          </el-table-column>


        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 采购订单详情查看对话框 -->
    <el-dialog title="采购订单详情" :visible.sync="detailsOpen" width="80%" append-to-body>
      <el-descriptions :column="2" border>
        <el-descriptions-item label="采购订单号">{{ orderDetails.poId }}</el-descriptions-item>
        <el-descriptions-item label="采购组织">{{ orderDetails.poOrg }}</el-descriptions-item>
        <el-descriptions-item label="存货编码">{{ orderDetails.itemId }}</el-descriptions-item>
        <el-descriptions-item label="存货名称">{{ orderDetails.itemName }}</el-descriptions-item>
        <el-descriptions-item label="规格型号">{{ orderDetails.spec }}</el-descriptions-item>
        <el-descriptions-item label="计量单位">{{ orderDetails.uom }}</el-descriptions-item>
        <el-descriptions-item label="供应商编码">{{ orderDetails.vendorId }}</el-descriptions-item>
        <el-descriptions-item label="供应商名称">{{ orderDetails.vendorName }}</el-descriptions-item>
        <el-descriptions-item label="订单数量">{{ orderDetails.poNum }}</el-descriptions-item>
        <el-descriptions-item label="已打码数量">{{ orderDetails.codeNum }}</el-descriptions-item>
        <el-descriptions-item label="未打码数量">{{ orderDetails.notcodeNum }}</el-descriptions-item>
        <el-descriptions-item label="剩余数量">{{ orderDetails.remainingNum }}</el-descriptions-item>
        <el-descriptions-item label="已送料数量">{{ orderDetails.payoffNum }}</el-descriptions-item>
        <el-descriptions-item label="已拒收数量">{{ orderDetails.rejectNum }}</el-descriptions-item>
        <el-descriptions-item label="已退货数量">{{ orderDetails.returnNum }}</el-descriptions-item>
        <el-descriptions-item label="已收货数量">{{ orderDetails.receivedNum }}</el-descriptions-item>
        <el-descriptions-item label="到货状态">
          <el-tag :type="getReceiveStatusType(orderDetails.receivedStatus)">
            {{ getReceiveStatusText(orderDetails.receivedStatus) }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="创建时间">{{ parseTime(orderDetails.createdAt, '{y}-{m}-{d} {h}:{i}:{s}') }}</el-descriptions-item>
        <el-descriptions-item label="创建人">{{ orderDetails.createdPerson }}</el-descriptions-item>
        <el-descriptions-item label="更新时间">{{ parseTime(orderDetails.updatedAt, '{y}-{m}-{d} {h}:{i}:{s}') }}</el-descriptions-item>
      </el-descriptions>
      <div slot="footer" class="dialog-footer">
        <el-button @click="detailsOpen = false">关 闭</el-button>
      </div>
    </el-dialog>




    <!-- 生成箱码对话框 -->
    <el-dialog title="生成箱码" :visible.sync="generateBoxCodeOpen" width="80%" append-to-body>
      <el-form ref="generateBoxCodeForm" :model="generateBoxCodeForm" :rules="generateBoxCodeRules" label-width="120px">
        <el-form-item label="采购订单号" prop="poId">
          <el-input v-model="generateBoxCodeForm.poId" placeholder="采购订单号" disabled />
        </el-form-item>
        <el-form-item label="标箱数量" prop="boxNum">
          <el-input-number
            v-model="generateBoxCodeForm.boxNum"
            placeholder="请输入标箱数量"
            :min="1"
            :max="generateBoxCodeForm.poNum"
            style="width: 100%"
            @change="calculateBoxCount"
          />
        </el-form-item>
        <el-form-item label="箱数" prop="boxCount">
          <el-input v-model="generateBoxCodeForm.boxCount" placeholder="自动计算" disabled />
        </el-form-item>
        <el-form-item label="本次打码数量" prop="codeNum">
          <el-input-number
            v-model="generateBoxCodeForm.codeNum"
            placeholder="请输入本次打码数量"
            :min="1"
            :max="generateBoxCodeForm.notcodeNum"
            style="width: 100%"
          />
        </el-form-item>
        <el-form-item label="计量单位" prop="uom">
          <el-input v-model="generateBoxCodeForm.uom" placeholder="计量单位" disabled />
        </el-form-item>
        <el-form-item label="未打码数量" prop="notcodeNum">
          <el-input v-model="generateBoxCodeForm.notcodeNum" placeholder="未打码数量" disabled />
        </el-form-item>
        <el-form-item label="生成日期" prop="generateDate">
          <el-date-picker
            v-model="generateBoxCodeForm.productionDate"
            type="date"
            placeholder="选择生成日期"
            value-format="yyyy-MM-dd"
            style="width: 100%"
          />
        </el-form-item>
        <el-form-item label="批次号" prop="batch">
          <el-input v-model="generateBoxCodeForm.batch"  disabled />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitGenerateBoxCode">确 定</el-button>
        <el-button @click="cancelGenerateBoxCode">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPurchaseOrders, getPurchaseOrders, delPurchaseOrders, addPurchaseOrders, updatePurchaseOrders, generatePoId } from "@/api/purchase/purchaseOrders"
import {
  batchdelPurchaseOrders,
  deletePurchaseOrderDetails,
  getPurchaseOrdersDetailInfo,
  generateBoxCode,
  generateBatchCode, generateBoxCodes,
} from "../../../api/purchase/purchaseOrders";

export default {
  name: "PurchaseOrders",
  data() {
    return {
      // 生成箱码对话框
      generateBoxCodeOpen: false,
      generateBoxCodeForm: {
        poId: undefined,
        boxNum: undefined,
        boxCount: 0,
        codeNum: undefined,
        uom: undefined,
        notcodeNum: 0,
        productionDate: undefined,
        batch: undefined
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedPurchaseOrdersDetails: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购订单表格数据
      purchaseOrdersList: [],
      // 采购订单表格数据
      purchaseOrdersDetailsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示详情弹出层
      detailsOpen: false,
      // 当前查看的订单详情
      orderDetails: {},
      // 是否为修改模式
      isEdit: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        poId: null,
        poOrg: null,
        itemId: null,
        itemName: null,
        vendorName: null,
        createdAt: null,
        createdPerson: null
      },
      // 表单参数
      form: {},
      form1: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()

  },
  methods: {
    /*生成箱码*/
    handleGenerateBoxCode(row) {
      this.generateBoxCodeOpen = true;

      // 从当前行获取数据
      this.generateBoxCodeForm.poId = row.poId;
      this.generateBoxCodeForm.uom = row.uom;
      this.generateBoxCodeForm.itemId = row.itemId;
      this.generateBoxCodeForm.poNum = row.poNum;
      this.generateBoxCodeForm.notcodeNum = row.notcodeNum;
      this.generateBoxCodeForm.productionDate = this.parseTime(new Date(), '{y}-{m}-{d}');
      generateBatchCode().then(batchCode => {
        console.log("批次号"+batchCode);
        this.generateBoxCodeForm.batch = batchCode;
      });



    },

    /** 计算箱数 */
    calculateBoxCount() {
      if (this.generateBoxCodeForm.boxNum && this.generateBoxCodeForm.poNum) {
        let boxCount = Math.floor(this.generateBoxCodeForm.codeNum / this.generateBoxCodeForm.boxNum);
        if (this.generateBoxCodeForm.codeNum % this.generateBoxCodeForm.boxNum !== 0) {
          boxCount++;
        }
        this.generateBoxCodeForm.boxCount = boxCount;
      } else {
        this.generateBoxCodeForm.boxCount = 0;
      }
    },

    /** 提交生成箱码 */
    submitGenerateBoxCode() {
      console.log("生成箱码")
      this.$refs["generateBoxCodeForm"].validate(valid => {
        console.log(this.generateBoxCodeForm);
        if (valid) {
          // 验证本次打码数量不能超过未打码数量
          if (this.generateBoxCodeForm.codeNum > this.generateBoxCodeForm.notcodeNum) {
            this.$modal.msgError("本次打码数量不能超过未打码数量");
            return;
          }
          // 验证标箱数量不能大于本次打码数量
          if (this.generateBoxCodeForm.boxNum > this.generateBoxCodeForm.codeNum) {
            this.$modal.msgError("标箱数量不能大于本次打码数量");
            return;
          }
            generateBoxCodes(this.generateBoxCodeForm).then(response => {
              this.$modal.msgSuccess("生成箱码成功");
              this.generateBoxCodeOpen = false;
              this.getList(); // 刷新采购订单列表
            }).catch(error => {
              this.$modal.msgError("生成箱码失败: " + (error.message || error));
            });
        }
      });
    },

    /** 取消生成箱码 */
    cancelGenerateBoxCode() {
      this.generateBoxCodeOpen = false;
      this.resetGenerateBoxCodeForm();
    },

    /** 查询采购订单列表 */
    getList() {
      this.loading = true
      listPurchaseOrders(this.queryParams).then(response => {
        console.log(response.rows)
        this.purchaseOrdersList = response.rows

        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        poId: null,
        poOrg: null,
        itemId: null,
        itemName: null,
        spec: null,
        uom: null,
        vendorId: null,
        vendorName: null,
        poNum: null,
        codeNum: null,
        notcodeNum: null,
        remainingNum: null,
        payoffNum: null,
        rejectNum: null,
        returnNum: null,
        receivedNum: null,
        receivedStatus: null,
        createdAt: null,
        createdPerson: null,
        updatedAt: null
      }
      this.purchaseOrdersDetailsList = []
      this.isEdit = false;
      this.resetForm("form")
    },
    /** 获取当前用户信息 */
    getUserInfo() {
      this.form.createdPerson = "采购李经理"
      this.form.poOrg = "103"
      this.form.totalAmount='0'
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.isEdit = false;
      this.open = true
      this.title = "添加采购订单"
      // 生成采购订单号
      generatePoId().then(response => {
        const po = (response && (response.data !== undefined && response.data !== null)) ? response.data : response.msg
        this.form.poId = po
        this.open = true;
        this.title = "添加采购订单";
        console.log(response)
      });
      this.getUserInfo();
      this.getList()
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.isEdit = true;
      const poId = row.poId
      const itemId = row.itemId
      getPurchaseOrders(poId,itemId).then(response => {
        this.form = response.data
        this.purchaseOrdersDetailsList = response.data.purchaseOrdersDetailsList
        this.open = true
        this.title = "修改采购订单"
        // 重新计算订单总数
        this.calculateTotalAmount();
        console.log(this.form)
        console.log(this.purchaseOrdersDetailsList)
      })
      this.getList()
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.purchaseOrdersDetailsList = this.purchaseOrdersDetailsList
          if (this.isEdit) {
            updatePurchaseOrders(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addPurchaseOrders(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      console.log("这条编号"+row.id)
      const ids = row.id
      this.$modal.confirm('是否确认删除采购订单编号为"' + ids + '"的数据项？').then(function() {
        return delPurchaseOrders(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 批量删除按钮操作 */
    handleBatchDelete() {
      const ids = this.ids;
      console.log("选择多条编号"+ids)
      if (ids.length === 0) {
        this.$modal.msgError("请选择要删除的数据");
        return;
      }

      this.$modal.confirm('是否确认删除选中的' + ids.length + '条数据？').then(() => {
        return batchdelPurchaseOrders(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 采购订单序号 */
    rowPurchaseOrdersDetailsIndex({ row, rowIndex }) {
      row.index = rowIndex + 1
    },
    /** 采购订单添加按钮操作 */
    handleAddPurchaseOrdersDetails() {
      let obj = {}
      obj.itemId = ""
      obj.poNum = ""
      obj.codeNum = ""
      obj.notcodeNum = ""
      obj.payoffNum = ""
      obj.rejectNum = ""
      obj.returnNum = ""
      obj.receivedNum = ""
      obj.receivedStatus = ""
      obj.createdAt = ""
      obj.createdPerson = ""
      obj.updatedAt = ""
      this.purchaseOrdersDetailsList.push(obj)
    },
    /** 采购订单删除按钮操作 */
    handleDeletePurchaseOrdersDetails() {
      if (this.checkedPurchaseOrdersDetails.length == 0) {
        this.$modal.msgError("请先选择要删除的采购订单数据")
      } else {
        const purchaseOrdersDetailsList = this.purchaseOrdersDetailsList
        const checkedPurchaseOrdersDetails = this.checkedPurchaseOrdersDetails
        this.purchaseOrdersDetailsList = purchaseOrdersDetailsList.filter(function(item) {
          return checkedPurchaseOrdersDetails.indexOf(item.index) == -1
        })
      }
    },
    /** 复选框选中数据 */
    handlePurchaseOrdersDetailsSelectionChange(selection) {
      this.checkedPurchaseOrdersDetails = selection.map(item => item.index)
    },
     /** 导出按钮操作 */
     handleExport() {
       this.download('purchase/purchaseOrders/export', {
         ...this.queryParams
       }, `purchaseOrders_${new Date().getTime()}.xlsx`)
     },
     /** 查看订单详情 */
     handleViewDetails(row) {
       const poId = row.poId
       const itemId = row.itemId
       getPurchaseOrdersDetailInfo(poId,itemId).then(response => {
         this.orderDetails = response.data
         this.detailsOpen = true
         // console.log("返回前端详情数据"+this.orderDetails)
       })
     },
     /** 获取收货状态类型 */
     getReceiveStatusType(status) {
       const statusMap = {
         0: 'success',  // 已完成
         1: 'warning'   // 未完成
       }
       return statusMap[status] || 'info'
     },
     /** 获取收货状态文本 */
     getReceiveStatusText(status) {
       const statusMap = {
         0: '未完成',
         1: '已完成'
       }
       return statusMap[status] || '未知'
     },
    /** 计算订单总数 */
    calculateTotalAmount() {
      let total = 0;
      this.purchaseOrdersDetailsList.forEach(item => {
        if (item.poNum && !isNaN(item.poNum)) {
          total += parseInt(item.poNum);
        }
      });
      this.form.totalAmount = total;
    },
  }
}
</script>
